package com.wanxin.car.carmng.action;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.wanxin.car.carmng.dao.IntermediaryDaoImpl;
import com.wanxin.car.carmng.model.Intermediary;


/**
 * 修理厂
 * @author lqk
 */
@Controller("/inter")
public class IntermediaryAction {

	@Resource
	private IntermediaryDaoImpl dao;
	
	/**
	 * 保存
	 */
	@RequestMapping(value="/inter/save")
	public String save(@ModelAttribute Intermediary inter){
		dao.save(inter);
		return "redirect:/inter/list";
	}
	
	/**
	 * 删除
	 */
	@RequestMapping(value="/inter/delete")
	public String delete(@RequestParam() String id){
		dao.delete(id);
		return "redirect:/inter/list";
	}
	
	/**
	 * 列表
	 */
	@RequestMapping(value="/inter/list")
	public String list(Model m){
		m.addAttribute("datas", dao.gets());
		return "inter/list";
	}
	

	
	/**
	 * 新增 修改界面
	 */
	@RequestMapping(value="/inter/input")
	public String input(@RequestParam(required=false) String id,Model m){
		
		if( StringUtils.hasText(id) ){
			//update
			m.addAttribute("model", dao.get(id));
		} else {
			//new
		}
		
		return "inter/input";
	}

	public IntermediaryDaoImpl getDao() {
		return dao;
	}

	public void setDao(IntermediaryDaoImpl dao) {
		this.dao = dao;
	}
}
